Page({
  data: {
    userList: [],
    url:""
  },
  onLoad(query) {
    
    this.setData({
      url: getApp().globalData.url
    });


    //搜索框赋值
    this.setData({
      searchValue: query.searchValue
    })
    //然后请求后台去搜索
    this.handleSearch();
    

  },
  //输入框事件
  bindInputValue(e) {
    this.setData({
      searchValue: e.detail.value,
    })
  },
  //在页面中点击搜索按钮进行查询
  handleSearch() {
    let $this = this;
    dd.httpRequest({
      url: $this.data.url+"/user/getAllUserInfoByName",
      method: "GET",
      data: {
        name: this.data.searchValue
      },
      dataType: "json",
      success: function(res) {
        if(res.data.data.length > 0){
          //拿到数据
          let len = $this.data.userList.length;
          $this.$spliceData({ userList: [0, len,...res.data.data] })
          for(let i = 0;i < $this.data.userList.length;i++){
            let user = 'userList['+i+'].sex'
            if($this.data.userList[i].sex == 0){
              $this.setData({
                [user]:'女'
              })
            }else{
              $this.setData({
                [user]:'男'
              })
            }
          }
        }else{
          dd.showToast({
            type: 'exception',
            content: '请求数据为空，请稍后重试',
            duration: 2000
          })
        }
      },
      fail: function(res) {
        dd.showToast({
          type: 'exception',
          content: '操作失败，请检查网络',
          duration: 2000
        })
      }
    })
  },
  handleTapUser(e) {
    getApp().globalData.searchValue = e.target.dataset.ddId;
    // 重定向
    dd.redirectTo({
      url: "../mycourse",
    })
  }
})